<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>
        你喜欢谁<input type="checkbox" name="" id="ul">全选/全不选<br>
        <input type="checkbox" name="" id="li">胡歌
        <input type="checkbox" name="" id="li">彭于晏
        <input type="checkbox" name="" id="li">赵玉真
        <input type="checkbox" name="" id="li">韩立
        <input type="checkbox" name="" id="li">萧炎
        <button>反选</button>
    </div>
    <script>
        var ul = document.getElementById('ul')
        var li = document.querySelectorAll('#li')
        var btn = document.querySelector('button')
        // console.log(btn);
        btn.onclick = function () {
            // 反选
            for (let i = 0; i < li.length; i++) {
                li[i].checked = !li[i].checked
            }
        }
        // 全选
        ul.onclick=function(){
            for (let i = 0; i < li.length; i++) {
                li[i].checked = this.checked
            }
        }

        for (let i = 0; i < li.length; i++){
            li[i].onclick=function(){
                 flag=true;
                for (let i = 0; i < li.length; i++) {
                   console.log(this.checked);
                   if(!li[i].checked){
                     flag=false
                     break;
                   }
              }
              ul.checked=flag
            }
        }
    </script>
</body>

</html>